package com.vehicle.controller.userController;


import com.vehicle.pojo.Customers;
import com.vehicle.pojo.DTO.VehicleQueryDTO;
import com.vehicle.pojo.VO.CarVO;

import com.vehicle.result.PageResult;
import com.vehicle.result.Result;
import com.vehicle.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RequestMapping("/user")
@RestController
@Slf4j
public class UserController {
    @Autowired
    private CustomerService customerService;


    /**
     *  用户注册
     * @param customers 请求体
     * @return
     */
    @PutMapping("/SignIn")
    public Result SignIn(@RequestBody Customers customers) {
        log.info("用户注册页面");
        if (customers.getName() != null) {
            Boolean aBoolean = customerService.SignIn(customers);
            if (aBoolean == true) {
                return Result.success();
            } else {
                return Result.error("账号已存在");
            }
        }
        return Result.error("姓名不能为空");
    }


    /**
     * 用户登录
     * @param customers 请求体
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Customers customers){
        log.info("用户登录");
        Boolean b=customerService.login(customers);
        if(b == true){
            return Result.success();
        }else{
            return Result.error("用户名或者秘密错误");
        }
    }

    /**
     * 分页查询 ？
     * @param vehicleQueryDTO 请求参数
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> pageQuery(VehicleQueryDTO vehicleQueryDTO){
      PageResult pageResult = customerService.pageQuery(vehicleQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据Id查询车辆信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<CarVO> selectById(@PathVariable Long id){
        log.info("查询车辆信息");
        CarVO car = customerService.selectById(id);
        return Result.success(car);
    }



}
